<template>
	<view class="login-container">
		<uni-icons type="contact-filled" size="130" color="darkgray"></uni-icons>
		<button type="primary" open-type="getUserInfo" @getuserinfo="getuserinfo">一键登录</button>
		<text>登录后尽享更多权益</text>
		
	</view>
</template>

<script>
	import {mapMutations,mapState} from 'vuex'
	export default {
		name:"my-login",
		data() {
			return {
				
			};
		},
		computed:{
			...mapState('m_user',['userInfo'])
		},
		methods:{
			...mapMutations('m_user',['updateUserInfo']),
			
			getuserinfo(e){
				if(e.detail.errMsg=="getUserInfo:fail auth deny") return uni.$showMsg('您取消了登录授权！')
				this.updateUserInfo(e.detail.userInfo)
				// console.log(e.detail.userInfo);
				
				this.getToken(e.detail)
			},
			async getToken(info){
				 const [err,succ] = await uni.login().catch(err=>err)
				 console.log(info);
				 console.log(succ);
				 if(err || succ.errMsg!=="login:ok") return uni.$showMsg('登录失败')
				 
				 const query={
					 encryptedData:info.encryptedData,
					 rawData:info.rawData,
					 iv:info.iv,
					 signature:info.signature,
					 code:succ.code,
				 }
				 
				 console.log(query);
				 
				const res =await uni.$http.post('api/public/v1/users/wxlogin',query).catch(err=>err)
				console.log(res);
			}
		},
		
		
	}
</script>

<style lang="scss">
.login-container{
	display: flex;
	align-items: center;
	flex-direction: column;
	justify-content: center;
	height: 750rpx;
	background-color: white;
	position: relative;
	&::after{
		content:'';
		display: block;
		border-radius: 100%;
		background-color: #f5f5f5;
		height: 40px;
		width: 100%;
		position: absolute;
		bottom:0;
		transform: translateY(50%);
	}
	
	button{
		font-size: 18px;
		text-align: center;
		background-color: #ff0000;
		width: 90%;
		border-radius: 60px;
		margin-bottom: 10px;
		margin-top: 20px;
	}
	text{
		color: darkgray;
		font-size: 14px;
	}
}
</style>